<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://guodh.gitee.io/blog').hostname,
    root: '/blog/',
    scheme: 'Pisces',
    version: '7.7.1',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="编程语言种类繁多，要将各种语言分门别类，也是颇难。但是有一个分类的角度，就是看这门语言有没有GC。举几个例子  没有GC的语言C++，Rust… 有GC的语言JAVA，Go，Lua，Python，PHP…  GC语言作用可以看到在GC语言中，有大量业务代码所需要用到的语言。让程序员从管理内存的痛苦中解脱出来，估计是这类语言最大的愿景吧。愿望永远是美好的，但是现实总是残酷的。当我们享受机器替我们管理">
<meta property="og:type" content="article">
<meta property="og:title" content="JVM线上问题排查工具">
<meta property="og:url" content="https://guodh.gitee.io/blog/2018/03/03/2018/JVM%E7%BA%BF%E4%B8%8A%E9%97%AE%E9%A2%98%E6%8E%92%E6%9F%A5%E5%B7%A5%E5%85%B7/index.html">
<meta property="og:site_name" content="蛋蛋的小屋">
<meta property="og:description" content="编程语言种类繁多，要将各种语言分门别类，也是颇难。但是有一个分类的角度，就是看这门语言有没有GC。举几个例子  没有GC的语言C++，Rust… 有GC的语言JAVA，Go，Lua，Python，PHP…  GC语言作用可以看到在GC语言中，有大量业务代码所需要用到的语言。让程序员从管理内存的痛苦中解脱出来，估计是这类语言最大的愿景吧。愿望永远是美好的，但是现实总是残酷的。当我们享受机器替我们管理">
<meta property="og:locale">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/15201355406480.jpg">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/15201756754843.jpg">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/15201478920541.jpg">
<meta property="article:published_time" content="2018-03-03T14:32:00.000Z">
<meta property="article:modified_time" content="2018-03-11T14:23:43.000Z">
<meta property="article:author" content="RunningEgg">
<meta property="article:tag" content="JVM">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://olwr1lamu.qnssl.com/15201355406480.jpg">

<link rel="canonical" href="https://guodh.gitee.io/blog/2018/03/03/2018/JVM%E7%BA%BF%E4%B8%8A%E9%97%AE%E9%A2%98%E6%8E%92%E6%9F%A5%E5%B7%A5%E5%85%B7/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>JVM线上问题排查工具 | 蛋蛋的小屋</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">蛋蛋的小屋</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">来了就看看吧，没有刀剑只有故事</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-book">

    <a href="/blog/book/" rel="section"><i class="fa fa-fw fa-archive"></i>book</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://guodh.gitee.io/blog/2018/03/03/2018/JVM%E7%BA%BF%E4%B8%8A%E9%97%AE%E9%A2%98%E6%8E%92%E6%9F%A5%E5%B7%A5%E5%85%B7/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="RunningEgg">
      <meta itemprop="description" content="写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="蛋蛋的小屋">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          JVM线上问题排查工具
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2018-03-03 22:32:00" itemprop="dateCreated datePublished" datetime="2018-03-03T22:32:00+08:00">2018-03-03</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2018-03-11 22:23:43" itemprop="dateModified" datetime="2018-03-11T22:23:43+08:00">2018-03-11</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>编程语言种类繁多，要将各种语言分门别类，也是颇难。但是有一个分类的角度，就是看这门语言有没有GC。举几个例子</p>
<ul>
<li>没有GC的语言<br>C++，Rust…</li>
<li>有GC的语言<br>JAVA，Go，Lua，Python，PHP…</li>
</ul>
<h2 id="GC语言作用"><a href="#GC语言作用" class="headerlink" title="GC语言作用"></a>GC语言作用</h2><p>可以看到在GC语言中，有大量业务代码所需要用到的语言。<br>让程序员从管理内存的痛苦中解脱出来，估计是这类语言最大的愿景吧。愿望永远是美好的，但是现实总是残酷的。当我们享受机器替我们管理内存垃圾的轻松的时候，我们也不得不面对各种问题。</p>
<h4 id="GC问题1：STOP-THE-WORLD"><a href="#GC问题1：STOP-THE-WORLD" class="headerlink" title="GC问题1：STOP THE WORLD"></a>GC问题1：STOP THE WORLD</h4><p>什么是STOP THE WORLD？有一个很好的例子，当你的妈妈要给你打扫卧室的时候，一定会让你停止丢垃圾。（否则你妈妈肯定让你死的很难看。）</p>
<p>如何考虑减少STP（STOP THE WORLD缩写，以下都用STP指代）的时间，避免在业务高峰期出现STP的现象，这都是作为一名程序员所需要考虑的。</p>
<h4 id="GC问题2：OUT-OF-MEMORY"><a href="#GC问题2：OUT-OF-MEMORY" class="headerlink" title="GC问题2：OUT OF MEMORY"></a>GC问题2：OUT OF MEMORY</h4><p>内存溢出。机器永远无法像人一样思考各种前因后果，它只会按照一定的逻辑进行处理。然而，往往有些时候，一些错误的业务逻辑，导致垃圾没有及时清理，容器占用过多的内存，而威胁到了操作系统。那么很对不起，机器就只能把容器给kill掉了。</p>
<h4 id="GC问题小结："><a href="#GC问题小结：" class="headerlink" title="GC问题小结："></a>GC问题小结：</h4><p>铺垫了那么多，说明了两个问题：</p>
<ol>
<li>GC有利有弊</li>
<li>作为一名GC语言的开发者，你必须去处理GC问题所带来的弊端</li>
</ol>
<h2 id="JVM线上问题排查工具"><a href="#JVM线上问题排查工具" class="headerlink" title="JVM线上问题排查工具"></a>JVM线上问题排查工具</h2><p>作为一个JVM语言开发者，其实是挺幸运的一件事儿。因为JVM负担起了GC的任务，将更多的问题抛给了JVM层。JVM提供给了开发者不同的GC收集器，开发者可以根据不同的使用场景来配置使用不同的GC收集器，甚至有好多的公司提供了不同的JVM选型（例如，R大的公司 <a href="https://cn.azul.com/">https://cn.azul.com/</a> ）提供了更高效的GC收集。</p>
<p>同时，JVM提供了很多工具，方便开发者来发现解决GC带来的各种问题。逼逼了这么久，终于到了展示一些实用工具的时候了。那么接下来，笔者将按照自己排查问题的思路，写下如何使用这些工具。</p>
<h3 id="1-查看日志"><a href="#1-查看日志" class="headerlink" title="1.查看日志"></a>1.查看日志</h3><p>启动时添加参数：**-XX:PrintGCDetails**</p>
<p>当线上发生问题的时候，第一步永远是观察GC日志，日志中记录了太多有价值的信息。看日志的前提，当然是理解日志。不同的收集器打印的日志，格式不同，但大体一样。</p>
<p>先来看第一个：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">58</span>:<span class="number">27.325</span>+0800: <span class="number">2432.757</span>: [ParNew: 4909K-&gt;343K(4928K), <span class="number">0.0106576</span> secs] 123196K-&gt;118740K(176320K), <span class="number">0.0110674</span> secs] </span><br><span class="line">[Times: user=<span class="number">0.01</span> sys=<span class="number">0.00</span>, real=<span class="number">0.01</span> secs]</span><br></pre></td></tr></table></figure>
<img src="https://olwr1lamu.qnssl.com/15201355406480.jpg" alt="GC日志"/>


<p>第二个CMS收集器，处理老年代</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">28.559</span>+0800: <span class="number">2373.991</span>: [GC (CMS Initial Mark) [<span class="number">1</span> CMS-initial-mark: 158393K(171392K)] 159765K(176320K), <span class="number">0.0122127</span> secs] [Times: user=<span class="number">0.01</span> sys=<span class="number">0.00</span>, real=<span class="number">0.02</span> secs]</span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">28.571</span>+0800: <span class="number">2374.004</span>: [CMS-concurrent-mark-start]</span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">28.877</span>+0800: <span class="number">2374.309</span>: [CMS-concurrent-mark: <span class="number">0.306</span>/<span class="number">0.306</span> secs] [Times: user=<span class="number">0.31</span> sys=<span class="number">0.00</span>, real=<span class="number">0.30</span> secs]</span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">28.878</span>+0800: <span class="number">2374.310</span>: [CMS-concurrent-preclean-start]</span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">28.881</span>+0800: <span class="number">2374.314</span>: [CMS-concurrent-preclean: <span class="number">0.004</span>/<span class="number">0.004</span> secs] [Times: user=<span class="number">0.00</span> sys=<span class="number">0.00</span>, real=<span class="number">0.01</span> secs]</span><br><span class="line">2018-03-02T14:57:28.884+0800: 2374.317: [GC (CMS Final Remark) [YG occupancy: 1830 K (4928 K)]2018-03-02T14:57:28.885+0800: 2374.317: [Rescan (parallel) , 0.0085246 secs]2018-03-02T14:57:28.893+0800: 2374.325: [weak refs processing, 0.0013466 secs]2018-03-02T14:57:28.894+0800: 2374.327: [class unloading, 0.0853379 secs]2018-03-02T14:57:28.980+0800: 2374.412: [scrub symbol table, 0.0289180 secs]2018-03-02T14:57:29.009+0800: 2374.441: [scrub string table, 0.0021484 secs][1 CMS-remark: 158393K(171392K)] 160224K(176320K), 0.1484632 secs] [Times: user=0.15 sys=0.00, real=0.15 secs]</span><br><span class="line"></span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">29.035</span>+0800: <span class="number">2374.467</span>: [CMS-concurrent-sweep-start]</span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">29.147</span>+0800: <span class="number">2374.579</span>: [CMS-concurrent-sweep: <span class="number">0.112</span>/<span class="number">0.112</span> secs] [Times: user=<span class="number">0.11</span> sys=<span class="number">0.00</span>, real=<span class="number">0.11</span> secs]</span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">29.147</span>+0800: <span class="number">2374.580</span>: [CMS-concurrent-reset-start]</span><br><span class="line"><span class="number">2018</span>-<span class="number">03</span>-02T14:<span class="number">57</span>:<span class="number">29.148</span>+0800: <span class="number">2374.580</span>: [CMS-concurrent-reset: <span class="number">0.001</span>/<span class="number">0.001</span> secs] [Times: user=<span class="number">0.00</span> sys=<span class="number">0.00</span>, real=<span class="number">0.00</span> secs]</span><br></pre></td></tr></table></figure>
<h3 id="2-JStat-JVM-Statistics-Monitoring-Tool"><a href="#2-JStat-JVM-Statistics-Monitoring-Tool" class="headerlink" title="2.JStat (JVM Statistics Monitoring Tool)"></a>2.JStat (JVM Statistics Monitoring Tool)</h3><p>一般看完日志之后，都会想知道GC进行的次数以及GC所耗费的时间，甚至是当前heap中，不同区域的使用情况。这个时候就可以使用命令:<br>jstat -gcutil pid</p>
<img src="https://olwr1lamu.qnssl.com/15201756754843.jpg" alt="jstat"/>

<p>以上S0，S1代表Survivor0，Survivor1，E代表Eden，o代表老年代，M代表永生代<br>YGCT和FGCT分别代表，年轻代GC的时间，老年代GC的时间。GCT代表总的耗费时间。</p>
<h3 id="3-JMap-JVM-Memory-Map-for-java"><a href="#3-JMap-JVM-Memory-Map-for-java" class="headerlink" title="3.JMap (JVM Memory Map for java)"></a>3.JMap (JVM Memory Map for java)</h3><p>当你发现JVM在不断的FULL GC的时候或者报错OOM了，这个时候一般都是发生了内存泄漏，就需要将堆dump下来。一般的操作步骤：</p>
<ol>
<li>获取java的进程id（pid）</li>
<li>dump堆</li>
<li>使用工具分析dump文件</li>
</ol>
<h4 id="获取java的进程id（pid）"><a href="#获取java的进程id（pid）" class="headerlink" title="获取java的进程id（pid）"></a>获取java的进程id（pid）</h4><p>可以使用命令：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -ef | grep java</span><br></pre></td></tr></table></figure>
<p>输入之后可以看到，以下结果。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">501</span>   <span class="number">555</span>     <span class="number">1</span>   <span class="number">0</span> Thu10AM ??         <span class="number">1</span>:<span class="number">49.96</span> /usr/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=<span class="number">75</span> -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Djava.awt.headless=<span class="keyword">true</span> -Dfile.encoding=UTF-<span class="number">8</span> -Djna.nosys=<span class="keyword">true</span> -Dio.netty.noUnsafe=<span class="keyword">true</span> -Dio.netty.noKeySetOptimization=<span class="keyword">true</span> -Dlog4j.shutdownHookEnabled=<span class="keyword">false</span> -Dlog4j2.disable.jmx=<span class="keyword">true</span> -Dlog4j.skipJansi=<span class="keyword">true</span> -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/usr/local/Cellar/elasticsearch/<span class="number">5.0</span><span class="number">.1</span>/libexec -cp /usr/local/Cellar/elasticsearch/<span class="number">5.0</span><span class="number">.1</span>/libexec/lib/elasticsearch-<span class="number">5.0</span><span class="number">.1</span>.jar:/usr/local/Cellar/elasticsearch/<span class="number">5.0</span><span class="number">.1</span>/libexec/lib/org.elasticsearch.bootstrap.Elasticsearch</span><br><span class="line"><span class="number">501</span>   <span class="number">722</span>     <span class="number">1</span>   <span class="number">0</span> Thu10AM ??         <span class="number">2</span>:<span class="number">31.69</span> /Applications/Nutstore.app/Contents/Resources/NutstoreJavaBE.app/Contents/MacOS/JavaAppLauncher --delayLaunch <span class="number">15</span> --retina --java-socket /Users/guodanhao/Library/Group Containers/net.nutstore.osxapp.socket_group/java_s.sock --cocoa-socket /Users/guodanhao/Library/Group Containers/net.nutstore.osxapp.socket_group/cocoa_s.sock</span><br><span class="line"><span class="number">501</span> <span class="number">17141</span> <span class="number">97476</span>   <span class="number">0</span>  <span class="number">3</span>:02PM ttys003    <span class="number">0</span>:<span class="number">00.00</span> grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn java</span><br></pre></td></tr></table></figure>

<p>或者结合JVM提供的工具JPS，直接输入:jps (JVM Process status)<br>(pid + 应用名)</p>
<h4 id="dump堆"><a href="#dump堆" class="headerlink" title="dump堆"></a>dump堆</h4><p>使用JMap来dump堆。<br>使用命令：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">jmap -dump:format=b,file=java.hprof <span class="number">555</span>（第一步获取的pid）</span><br></pre></td></tr></table></figure>
<p>当使用的是Jetty的时候，就需要用：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo -u jetty jmap -dump:format=b,file=java.hprof <span class="number">30201</span></span><br></pre></td></tr></table></figure>
<p>会在当前目录生成java.hprof的文件.使用scp或者跳板机下载java.hprof</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">scp root<span class="meta">@ip</span>:/opt/jetty/java.hprof /本机地址</span><br></pre></td></tr></table></figure>
<h4 id="分析dump文件"><a href="#分析dump文件" class="headerlink" title="分析dump文件"></a>分析dump文件</h4><p>使用Jhat或者MAT来分析。<br>推荐使用MAT，它是Eclipse的一个插件，强大的可视化功能</p>
<img src="https://olwr1lamu.qnssl.com/15201478920541.jpg" alt="GC日志"/>

<p>不用以为它只有简单的图形展示功能，如何使用可以看下面这个介绍<br><a href="http://childe.net.cn/2017/03/24/MAT-Memory-Analyzer-Tool-%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/">http://childe.net.cn/2017/03/24/MAT-Memory-Analyzer-Tool-%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/</a></p>
<p>除了能dump出堆，jmap还能很好的查看heap的配置，以及年轻代和老年代的使用情况。<br>命令:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">jmap -heap pid</span><br></pre></td></tr></table></figure>
















    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/JVM/" rel="tag"># JVM</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2018/02/25/2018/rocketmq%E9%97%AE%E9%A2%98/" rel="prev" title="RocketMq中MessageQueue的分配">
      <i class="fa fa-chevron-left"></i> RocketMq中MessageQueue的分配
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2018/03/11/2018/CMS%E6%94%B6%E9%9B%86%E5%99%A8vsG1%E6%94%B6%E9%9B%86%E5%99%A8/" rel="next" title="CMS收集器 VS G1收集器">
      CMS收集器 VS G1收集器 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#GC%E8%AF%AD%E8%A8%80%E4%BD%9C%E7%94%A8"><span class="nav-number">1.</span> <span class="nav-text">GC语言作用</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#GC%E9%97%AE%E9%A2%981%EF%BC%9ASTOP-THE-WORLD"><span class="nav-number">1.0.1.</span> <span class="nav-text">GC问题1：STOP THE WORLD</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#GC%E9%97%AE%E9%A2%982%EF%BC%9AOUT-OF-MEMORY"><span class="nav-number">1.0.2.</span> <span class="nav-text">GC问题2：OUT OF MEMORY</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#GC%E9%97%AE%E9%A2%98%E5%B0%8F%E7%BB%93%EF%BC%9A"><span class="nav-number">1.0.3.</span> <span class="nav-text">GC问题小结：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JVM%E7%BA%BF%E4%B8%8A%E9%97%AE%E9%A2%98%E6%8E%92%E6%9F%A5%E5%B7%A5%E5%85%B7"><span class="nav-number">2.</span> <span class="nav-text">JVM线上问题排查工具</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-%E6%9F%A5%E7%9C%8B%E6%97%A5%E5%BF%97"><span class="nav-number">2.1.</span> <span class="nav-text">1.查看日志</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-JStat-JVM-Statistics-Monitoring-Tool"><span class="nav-number">2.2.</span> <span class="nav-text">2.JStat (JVM Statistics Monitoring Tool)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-JMap-JVM-Memory-Map-for-java"><span class="nav-number">2.3.</span> <span class="nav-text">3.JMap (JVM Memory Map for java)</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96java%E7%9A%84%E8%BF%9B%E7%A8%8Bid%EF%BC%88pid%EF%BC%89"><span class="nav-number">2.3.1.</span> <span class="nav-text">获取java的进程id（pid）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#dump%E5%A0%86"><span class="nav-number">2.3.2.</span> <span class="nav-text">dump堆</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%86%E6%9E%90dump%E6%96%87%E4%BB%B6"><span class="nav-number">2.3.3.</span> <span class="nav-text">分析dump文件</span></a></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">RunningEgg</p>
  <div class="site-description" itemprop="description">写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">89</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">tags</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="mailto:guodh_1@163.com" title="E-Mail → mailto:guodh_1@163.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">RunningEgg</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  















  

  

</body>
</html>
